package com.ijiuchuang.jc_localization.view.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ijiuchuang.jc_localization.R;
import com.ijiuchuang.jc_localization.bean.entity.OpenSourceLicense;
import com.ijiuchuang.jc_localization.view.adapter.OpenSourceRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class OpenSourceFragment extends Fragment {

    @BindView(R.id.open_source_recycler)
    RecyclerView mRecyclerView;

    public OpenSourceFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_open_source, container, false);
        ButterKnife.bind(this, view);

        String[] names = getResources().getStringArray(R.array.OpenSourceLicenseName);
        String[] descriptions = getResources().getStringArray(R.array.OpenSourceLicenseDescription);
        List<OpenSourceLicense> licenses = new ArrayList();

        for (int i = 0; i < names.length; i ++) {
            OpenSourceLicense license = new OpenSourceLicense(names[i], descriptions[i]);
            licenses.add(license);
        }

        OpenSourceRecyclerAdapter mRecyclerAdapter = new OpenSourceRecyclerAdapter(getActivity(), R.layout.recycler_item_open_source, licenses);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setAdapter(mRecyclerAdapter);
        return view;
    }

}
